home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
pc
/
Code
/
Chapter Code.exe
/
Chapter10
/
MultiViewpoints1Panel.java
< prev
next >
Wrap
Text File
|
2000-07-13
|
4KB
|
161 lines
package applets;
import shout3d.*;
import shout3d.core.*;
import custom_nodes.*;
public class MultiViewpoints1Panel extends Shout3DPanel implements DeviceObserver {
int pixelStartX;
int pixelStartY;
int pixelEndX;
int pixelEndY;
TargetViewpoint[] cameras = new TargetViewpoint [3];
int currentCam = 1;
int totalCams = 1;
public MultiViewpoints1Panel(Shout3DApplet applet){
super(applet);
}
public void customInitialize() {
addDeviceObserver(this,"DeviceInput", null);
cameras[currentCam-1] = (TargetViewpoint) getCurrentBindableNode("Viewpoint");
}
protected void finalize() {
removeDeviceObserver(this,"DeviceInput");
}
public boolean onDeviceInput(DeviceInput di, Object userData) {
//if mouse input
if (di instanceof MouseInput) {
MouseInput mi = (MouseInput) di;
switch (mi.which){
case MouseInput.DOWN:
pixelStartX = mi.x;
pixelStartY = mi.y;
return true;
case MouseInput.DRAG:
//if left button used
if(mi.button == 0) {
pixelEndX = mi.x;
pixelEndY = mi.y;
int dragDistanceX = pixelEndX - pixelStartX;
int dragDistanceY = pixelEndY - pixelStartY;
float headingDelta = dragDistanceX/70f;
float pitchDelta = dragDistanceY/70f;
float temp = cameras[currentCam-1].heading.getValue() - headingDelta;
cameras[currentCam-1].heading.setValue(temp);
temp = cameras[currentCam-1].pitch.getValue() - pitchDelta;
cameras[currentCam-1].pitch.setValue(temp);
pixelStartY = pixelEndY;
pixelStartX = pixelEndX;
return true;
}//end of 0 if
//if right button used
if(mi.button == 1) {
pixelEndY = mi.y;
int dragDistanceY = pixelEndY - pixelStartY;
float distanceDelta = dragDistanceY/150f;
float temp = cameras[currentCam-1].distance.getValue() + distanceDelta;
cameras[currentCam-1].distance.setValue(temp);
pixelStartY = pixelEndY;
return true;
}//end of 1 if
}//end of switch
return false;
}//end of mouse input
if (di instanceof KeyboardInput) {
KeyboardInput ki = (KeyboardInput) di;
if (ki.which == KeyboardInput.PRESS) {
if (ki.key == 'c' || ki.key == 'C') {
//create new camera and
//add it to the array
if (totalCams < 3) {
totalCams++;
currentCam = totalCams;
cameras[currentCam-1] = new TargetViewpoint(this);
//add to scene and bind
Node [] kids = {cameras[currentCam-1]};
getScene().addChildren(kids);
cameras[currentCam-1].isBound.setValue(true);
cameras[currentCam-1].center.setValue(cameras[0].center.getValue());
}
return true;
}//end of 'c'
if (ki.key == '1') {
if (totalCams >= 1) {
//bind camera 1
currentCam = 1;
cameras[currentCam- 1].isBound.setValue(true);
}
return true;
}//end of '1'
if (ki.key == '2') {
if (totalCams >= 2) {
currentCam = 2;
cameras[currentCam- 1].isBound.setValue(true);
}
return true;
}//end of '2'
if (ki.key == '3') {
if (totalCams >= 3) {
currentCam = 3;
cameras[currentCam- 1].isBound.setValue(true);
}
return true;
}//end of '3'
return false;
}
return false;
}//end of keyboard input
return false;
}//end of onDeviceInput()
}//end of class